<?php
if ( !defined( "IN_OP" ) )
{
    exit( "You can't access this file directly..." );
}
require_once( "class_3d/CheckMode_3d.php" );
$gametype = intval( getvar( "gametype" ) );
$chkGametype = chkGametype( $gametype );
$chk = new CheckMode_3d( $curruser['acl'], 1, $gametype );
$chk->checkShow3dPage();
$show3D3S = $chk->show3D3S;
unset( $chk );
$tbl = $g_gametype_3d[$gametype]['en'];
$tblName = $g_gametype_3d[$gametype]['ch'];
include_once( "class/function_3d.php" );
$ui = new UI_3D( true );
$tpl = new Template2();
$conf = new Config();
$postTime = $conf->get( "paper_post_bet" );
$today = date( "Hi" ) <= $postTime ? date( "Y-m-d", strtotime( "-1 day" ) ) : date( "Y-m-d" );
$showDate = getvar( "showDate" );
$showDate = $showDate == "" ? $today : $showDate;
if ( $conf->get( "calcbet_{$tbl}" ) == 1 )
{
    $ui->showErrorPage( "{$tblName}颁奖过帐中，请稍後再使用本功能！", true );
    exit();
}
else if ( $curruser['enabled'] == 0 )
{
    $ui->showErrorPage( "帐号已被暂停使用" );
    exit();
}
else if ( !is_date( $showDate ) )
{
    exit( "error date type" );
}
else if ( strtotime( $showDate ) < strtotime( "-10 day" ) )
{
    $ui->showErrorPage( "只能查询10天之内的帐" );
    exit();
}
require_once( "class_3d/MyLotto_3d.php" );
require_once( "class_3d/Bet_3d.php" );
$MyLotto_3d = new MyLotto_3d( $gametype );
$Bet_3d = new Bet_3d( $gametype );
$tmp = "";
$sum_amount = 0;
$sum_result = 0;
$sum_back1 = 0;
$paperShowOpen = getPaperMinDate( 0 - 1 );
$title = "<span style=\"padding:9px 0px 0px 8px;\" class=\"head1\">{$tblName}帐户历史</span>";
$rs = getdb( "SELECT * FROM {$MyLotto_3d->table_name} WHERE open='{$showDate}' AND startbet <= '".date( "Y-m-d H:i:s" )."' && open >= '{$paperShowOpen}' ORDER BY openbet DESC,round DESC" );
if ( $rs->eof )
{
    $list = "<tr class=\"row1\"><td colspan=\"5\">查无".$tblName."资料</td></tr>";
}
else
{
    $list = "";
}
$tblChk = $Bet_3d->table_name;
while ( !$rs->eof )
{
    $lotto_id = $rs->f['id'];
    $open = $rs->f['openbet'];
    $round = $rs->f['round'];
    $openChk = $rs->f['open'];
    if ( $openChk == $today )
    {
        $Bet_3d->table_name = $tblChk;
    }
    else
    {
        $Bet_3d->table_name = "x".$tblChk;
    }
    $totalResult = $Bet_3d->getBetHistoryResult( $curruser['id'], $lotto_id );
    $list .= "<tr class=\"td2\">";
    if ( $rs->f['calcbet'] == 1 )
    {
        $list .= "<td colspan=\"5\" class=\"td_cen_b\">".$open." 期数:".$round."颁奖过帐中</td>";
        $rs->movenext();
        continue;
    }
    if ( 0 < $totalResult['amount'] )
    {
        if ( $show3D3S == 2 )
        {
            $showUrl = "?op=member_5h&fp=view&lotto_id=".$lotto_id."&gametype=".$gametype;
        }
        else
        {
            $showUrl = "?op=member_3d&fp=view&lotto_id=".$lotto_id."&gametype=".$gametype;
        }
        $list .= "<td nowrap><a href=\"".$showUrl."\"><font color=\"#cc0000\"><b>".$open."</b></font></a></td>";
        $list .= "<td nowrap align=\"left\"><a href=\"".$showUrl."\"><font color=\"#cc0000\"><b>".$round."</b></font></a></td>";
    }
    else
    {
        $list .= "<td nowrap><font color=\"#cc0000\">".$open."</font></td>";
        $list .= "<td nowrap align=\"left\"><font color=\"#cc0000\">".$round."</font></td>";
    }
    $list .= "<td align=\"right\">".$totalResult['amount']."</td>";
    $list .= "<td align=\"right\">".round( $totalResult['a1'], 2 )."</td>";
    $list .= "<td align=\"right\">".say_numbercolor( round( $totalResult['b1'], 2 ) )."</td>";
    $list .= "</tr>";
    $sum_amount += $totalResult['amount'];
    $sum_result += $totalResult['b1'];
    $sum_back1 += $totalResult['a1'];
    $rs->movenext();
}
$tpl->load( "main", "history_round.htm" );
$tpl->set( array( "list" => $list, "sum_amount" => $sum_amount, "sum_result" => say_numbercolor( round( $sum_result, 2 ) ), "sum_back1" => round( $sum_back1, 2 ), "sum_all" => round( $sum_result + $sum_back1, 2 ), "gametypeStr" => $tblName, "gametype" => $gametype, "title" => $title ) );
$ui->header();
$ui->showNews3D( $curruser['acl'] ,1);
$tpl->show( "main" );
$ui->footer();
?>